package cz.muni.fi.pa165.dundd.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

/**
 *
 * @author xszanto1, Šimon Demočko
 */
@Entity
public class Hero implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    private String password;
    private int xp;
    @Column(nullable = false, updatable = false)
    private String authority = "ROLE_HERO";
    @ManyToMany(cascade = CascadeType.REMOVE)
    private List<HeroRole> roles;
    @ManyToOne(optional = true)
    private Troop myParty;

    public Hero() {
        xp = 0;
        roles = new ArrayList<>();
    }

    //<editor-fold defaultstate="collapsed" desc="getset">
    public String getAuthority() {
        return "ROLE_HERO";
    }

    public void setAuthority(String authority) {
        this.authority = authority;
    }

    public List<HeroRole> getRoles() {
        return roles;
    }

    public void setRoles(List<HeroRole> roles) {
        this.roles = roles;
    }

    public void addRole(HeroRole role) {
        this.roles.add(role);
    }

    public void removeRole(HeroRole role) {
        this.roles.remove(role);
    }

    public Troop getMyParty() {
        return myParty;
    }

    public void setMyParty(Troop myParty) {
        this.myParty = myParty;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getXp() {
        return xp;
    }

    public void setXp(int xp) {
        this.xp = xp;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    //</editor-fold>

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Hero)) {
            return false;
        }
        Hero other = (Hero) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Player{" + "id=" + id + ", name=" + name + ", xp=" + xp + '}';
    }

    public Hero(String name, int xp) {
        this.name = name;
        this.xp = xp;
    }
}
